﻿using Android.Telephony;
using AndroidApp = Android.App;

namespace OpenAiMobile.Platforms.Android
{
    public class AndroidAppService
    {
        //获取手机号
        public static string GetPhoneNumber()
        {
            var context = AndroidApp.Application.Context;
            var manager = TelephonyManager.FromContext(context);
            return manager?.Line1Number;
        }

        //获取设备Id
        public static string GetAndroidId()
        {
            var context = AndroidApp.Application.Context;
            var manager = TelephonyManager.FromContext(context);
            var deviceId = $"{manager?.GetImei(0)}{manager?.GetMeid(0)}";
            return string.IsNullOrWhiteSpace(deviceId)
                ? $"{Guid.NewGuid()}".Replace("-", "")
                : deviceId;
        }
    }
}
